<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/base.js"></script>
</head>
<body>
<h1>用户登录</h1>
用户名: <input type="text" id="username"/><br>
密码: <input type="password" id="password"/><br>
<button onclick="onSignInClick();">登录</button><button onclick="goToSignUp();">注册</button>
<script>
    function goToSignUp() {
        window.location.href="signUp.html";
        }
    function onSignInClick() {
        let url="http://localhost:9001/Demo/user/signIn";
        let method="post";
        let requestJson={};
        requestJson.signInName=document.getElementById("username").value;
        requestJson.password=document.getElementById("password").value;
        $.rest(method,url,requestJson,function(r){
            if (r.code==200){
                //学生登录
                //学生登录后应该引导到后续页面
                let id=r.result.user.id;
                let username=r.result.user.username;
                let token=r.result.token;
                localStorage.setItem("id",id);
                localStorage.setItem("username",username);
                localStorage.setItem("token",token);
                window.location.href="student.html";
            }else if (r.code==201){
                //教师登录
                //教师登录后应该引导到后续页面
                location.href="teacher.html";
            }else if (r.code==501){
                //用户登录信息有误
                alert("用户登录信息有误");
            }
            });

        }
</script>
</body>
</html>